using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Business.Entities.Rules;

namespace OR.Lazarus.Business.Entities.Rules.Lazarus
{
	/// <summary>
	/// Defines rules about the generation of Primary Keys.
	/// </summary>
   public class FKRuleDetail : EntityBase
   {
		protected System.String mName;
		protected System.Boolean mUseEntityName;
		protected string mPrefix;
		protected string mSuffix;
		protected string mDescription;

		public FKRuleDetail()
		{
	
		}
	
		/// <summary>
		/// 
		/// </summary>
		public System.String Name
		{
			get
			{
				return ( mName );
			}
			set
			{
				mName = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public System.Boolean UseEntityName
		{
			get
			{
				return ( mUseEntityName );
			}
			set
			{
				mUseEntityName = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Prefix
		{
			get
			{
				return ( mPrefix );
			}
			set
			{
				mPrefix = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Suffix
		{
			get
			{
				return ( mSuffix );
			}
			set
			{
				mSuffix = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Description
		{
			get
			{
				return ( mDescription );
			}
			set
			{
				mDescription = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mName = DataUtility.GetString( pSource, "name" );
			mUseEntityName = DataUtility.GetBool( pSource, "use-entity-name", false );
			mPrefix = DataUtility.GetString( pSource, "prefix" );
			mSuffix = DataUtility.GetString( pSource, "suffix" );
			XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "lcz:description", PersistenceConfig.Namespaces );
			
			if ( vDescription != null )
			{
				mDescription = vDescription.InnerText;
			}
			
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "lcz", "fk-rule", "http://schemas.icitadel.com/Lazarus/Rules.xsd" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mName ) )
			{
				vNewElement.SetAttribute( "name", mName );
			}
					
			vNewElement.SetAttribute( "use-entity-name", mUseEntityName.ToString() );
			if ( !String.IsNullOrEmpty( mPrefix ) )
			{
				vNewElement.SetAttribute( "prefix", mPrefix );
			}
					
			if ( !String.IsNullOrEmpty( mSuffix ) )
			{
				vNewElement.SetAttribute( "suffix", mSuffix );
			}
					
			if ( !String.IsNullOrEmpty( mDescription ) )
			{
				XmlElement	vDescription = p_docContext.CreateElement( "lcz", "description", "http://schemas.icitadel.com/Lazarus/Rules.xsd" );
				vDescription.InnerText = mDescription;
				vNewElement.AppendChild( vDescription );
			}
					

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.FKRuleDetail v_oReturn = new Derived.FKRuleDetail();
			
			v_oReturn.Name = mName;
			v_oReturn.UseEntityName = mUseEntityName;
			v_oReturn.Prefix = mPrefix;
			v_oReturn.Suffix = mSuffix;
			v_oReturn.Description = mDescription;
			
			// FK Values

			// Collections
			
			return ( v_oReturn );
		}

		public virtual Derived.FKRuleDetail CloneTyped()
		{
			return ( ( Derived.FKRuleDetail )this.Clone() );
		}
   }
}
   